package itbour.onetouchshow.activity.version1_3;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andview.adapter.BaseRecyclerHolder;
import com.andview.refreshview.XRefreshView;
import com.andview.refreshview.XRefreshViewFooter;
import com.google.gson.Gson;
import com.umeng.analytics.MobclickAgent;
import com.ys.uilibrary.utils.DisplayUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import itbour.onetouchshow.R;
import itbour.onetouchshow.adapter.FilterAdapter;
import itbour.onetouchshow.base.BaseRefreshAdapter;
import itbour.onetouchshow.base.CustomGifHeader;
import itbour.onetouchshow.base.mvp.MVPBaseActivity;
import itbour.onetouchshow.bean.DesignListBean;
import itbour.onetouchshow.bean.HomeDetailslBean;
import itbour.onetouchshow.bean.VideoConditionBean;
import itbour.onetouchshow.bean.eventbus.DetailsAction;
import itbour.onetouchshow.bean.page.Page;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.listener.MyRyItemListener;
import itbour.onetouchshow.service.ImagePorviderService;
import itbour.onetouchshow.utils.ImageLoader;
import itbour.onetouchshow.utils.JumpUtils;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.SpUtils;
import itbour.onetouchshow.utils.UIUtils;
import itbour.onetouchshow.view.ShowDialogUtils;

/**
 * Created by guoh on 2018/2/28.
 */

public class ClassifyListActivity extends MVPBaseActivity<ClassifyListContract.View, ClassifyListPresenter> implements ClassifyListContract.View {

    public static final int ON_REFRESH = 1;
    public static final int ON_LOAD = 2;
    public static final int NO_MORE = 3;
    public static final String CLASSIFY_ID = "CLASSIFY_ID";
    public static final String CLASSIFY_TITLE = "CLASSIFY_TITLE";
    public static final String SHOW_FILTER = "SHOW_FILTER";
    private static final int FAST_CLICK_DELAY_TIME = 2000;
    public int mPageIndex = 0;
    public int pullStatus;
    BaseRefreshAdapter baseRefreshAdapter;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R.id.xrefreshview)
    XRefreshView xrefreshview;
    @BindView(R.id.ry_time)
    RecyclerView ryTime;
    @BindView(R.id.ry_module)
    RecyclerView ryModule;
    @BindView(R.id.tv_filter_rule)
    TextView tvFilterRule;
    @BindView(R.id.ll_filter_layout)
    LinearLayout llFilterLayout;
    @BindView(R.id.tv_filter_name1)
    TextView tvFilterName1;
    @BindView(R.id.tv_filter_name2)
    TextView tvFilterName2;
    @BindView(R.id.ll_filter1)
    LinearLayout llFilter1;
    @BindView(R.id.ll_filter2)
    LinearLayout llFilter2;
    @BindView(R.id.iv_filter_rule)
    ImageView ivFilterRule;
    @BindView(R.id.ll_filter_rule)
    LinearLayout llFilterRule;
    private FilterAdapter filterAdapter1;
    private FilterAdapter filterAdapter2;
    /**
     * 根据ID 获取数据
     */
    private ArrayList<Integer> mids;
    /**
     * 数据源
     */
    private List<DesignListBean.ListBean> mdata = new ArrayList<>();
    /**
     * 后台数据
     */
    private DesignListBean designListBean;
    private Page page;
    //动画时间
    private int animationTime = 200;
    //两筛选条件
    private VideoConditionBean.Option filterRuleOption1;
    private VideoConditionBean.Option filterRuleOption2;
    //全部筛选条件
    private VideoConditionBean.Option allRuleOption1;
    private VideoConditionBean.Option allRuleOption2;
    //是否执行了动画
    private boolean executeTheAnimation = false;
    private ShowDialogUtils progressDialog;
    private long lastClickTime = 0L;
    private VideoConditionBean conditionBean;

    public static Intent getLaunchIntent(Context context, String title, ArrayList<Integer> id, boolean showFilter) {
        Intent intent = new Intent(context, ClassifyListActivity.class);
        intent.putIntegerArrayListExtra(CLASSIFY_ID, id);
        intent.putExtra(CLASSIFY_TITLE, title);
        intent.putExtra(SHOW_FILTER, showFilter);
        return intent;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.ac_classify_list;
    }


    @Override
    public void loadSucceed(String result) {
        progressDialog.dismissProgressDialog();
        showContentView();
        showXRefreshViewNetWorkSuccessView();
        page.finishLoad(true);
        designListBean = new Gson().fromJson(result, DesignListBean.class);
        List<DesignListBean.ListBean> resultData = designListBean.getList();
        //无数据显示empty view
        if (resultData == null || resultData.size() <= 0) {
            xrefreshview.stopRefresh();
            if (!xrefreshview.isEmptyViewShowing()) {
                xrefreshview.setEmptyView(R.layout.view_no_data);
                xrefreshview.enableEmptyView(true);
            }
            return;
        } else {
            xrefreshview.enableEmptyView(false);
        }

        DetailsAction detailsAction = new DetailsAction("main" + ClassifyListActivity.this, resultData);
        ImagePorviderService.startService(getViewContext(), detailsAction);


    }

    @Override
    public void loadFaild(String error) {
        progressDialog.dismissProgressDialog();
        page.finishLoad(false);
        showContentView();
        showXRefreshViewNetWorkErrorView();
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        setTitleText(getIntent().getStringExtra(CLASSIFY_TITLE));
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void dataEvent(DetailsAction detailsAction) {
        if (!detailsAction.getSubType().equals("main" + ClassifyListActivity.this)) {
            return;
        }

        if (detailsAction.getData().size() == 0) {
            if (designListBean != null && mPageIndex >= designListBean.getTotalPage() - 1) {
                return;
            }
            showEmptyView();
            return;
        }

        if (designListBean == null) {
            endNetRequse(detailsAction.getData());
        } else {
            endNetRequse(detailsAction.getData());
        }
    }

    public void endNetRequse(List<DesignListBean.ListBean> data) {
        showContentView();
        if (pullStatus == ON_LOAD) {
            mdata.addAll(data);
            xrefreshview.stopLoadMore();
        } else if (pullStatus == ON_REFRESH) {
            mdata = data;
            xrefreshview.stopRefresh();
            xrefreshview.setLoadComplete(false);
        }
        if (designListBean != null && mPageIndex >= designListBean.getTotalPage() - 1) {
            xrefreshview.setLoadComplete(true);
        }
        baseRefreshAdapter.notifyDataSetChanged(mdata);
        pullStatus = 1;
    }

    private void onLoadData() {
        //添加loading框以增加过渡体验
        if (progressDialog == null) {
            progressDialog = new ShowDialogUtils(this, R.style.dialog_transparent_style);
        }
        progressDialog.showProgressDialog();
        page = new Page() {
            @Override
            public void load(int param1, int param2) {
                L_.e("load" + param1);
                mPageIndex = param1;
                //Log.e("tag",""+getDurationKey()+""+getDurationValue()+""+getTmplTypeKey()+""+getTmplTypeValue());
                if (!getIntent().getBooleanExtra(SHOW_FILTER, false)) {
                    mPresenter.getDetailsList(ClassifyListActivity.this, mids, conditionBean.getDurationCondition().getRequestKey(), new Gson().toJson(conditionBean.getDurationCondition().getOptions().get(0).getValues()), conditionBean.getIndustryCondition().getRequestKey(), new Gson().toJson(conditionBean.getIndustryCondition().getOptions().get(0).getValues()));
                } else {
                    mPresenter.getDetailsList(ClassifyListActivity.this, mids, getDurationKey(), getDurationValue(), getTmplTypeKey(), getTmplTypeValue());
                }

                //showLoadingView();
            }

        };
        pullStatus = ON_REFRESH;
        if (mPresenter != null) {
            page.loadPage(true);
        }
    }

    @Override
    protected void initView() {
        super.initView();
        xrefreshview.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener() {
            @Override
            public void onRefresh(boolean isPullDown) {
                pullStatus = ON_REFRESH;
                if (mPresenter != null) {
                    page.loadPage(true);
                }
            }

            @Override
            public void onLoadMore(boolean isSilence) {
                UIUtils.getHandler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        pullStatus = ON_LOAD;
                        if (mPresenter != null) {
                            page.loadPage(false);
                        }
                    }
                }, AppConst.DELAYED_TIME);

            }
        });
        initRecycleView();
        initFilter();
        recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
            }

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    if (llFilterLayout.getVisibility() == View.GONE) return;
                    if (!executeTheAnimation && baseRefreshAdapter.getListData().size() >= AppConst.PAGE_SIZE) {
                        executeTheAnimation = true;
                        setFilterLayoutAlphaAnimation(1, 0, animationTime);
                        //上滑则缩起筛选条件 弹出筛选内容
//                        setFilterLayoutHeightAnimation(DisplayUtils.dip2px(getContext(),90), 0, animationTime);
                    }
                }
            }
        });
        onLoadData();

    }

    private void initRecycleView() {
        xrefreshview.setAutoRefresh(false);
        xrefreshview.setAutoLoadMore(true);
        xrefreshview.stopLoadMore(false);
        xrefreshview.setPullLoadEnable(true);
        xrefreshview.setMoveForHorizontal(true);
        CustomGifHeader header = new CustomGifHeader(getApplicationContext());
        xrefreshview.setEmptyView(R.layout.view_network_error);
        xrefreshview.setCustomHeaderView(header);

        baseRefreshAdapter = getBaseRefreshAdapter();
        if (baseRefreshAdapter == null) {
            return;
        }
        baseRefreshAdapter.setCustomLoadMoreView(new XRefreshViewFooter(getViewContext()));
        recyclerview.setHasFixedSize(true);
        //使用瀑布流布局,第一个参数 spanCount 列数,第二个参数 orentation 排列方向
        StaggeredGridLayoutManager recyclerViewLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        recyclerview.setLayoutManager(recyclerViewLayoutManager);
        recyclerview.setAdapter(baseRefreshAdapter);
        baseRefreshAdapter.setOnItemClickListener(new MyRyItemListener() {
            @Override
            public void onItemSelect(Object o) {
                if (System.currentTimeMillis() - lastClickTime < FAST_CLICK_DELAY_TIME) {
                    return;
                }
                lastClickTime = System.currentTimeMillis();
                DesignListBean.ListBean listBean = (DesignListBean.ListBean) o;
                JumpUtils.goToVideoPlayer(ClassifyListActivity.this, listBean.getId());
            }
        });


    }

    private void initFilter() {
        filterAdapter1 = new FilterAdapter(getViewContext());
        filterAdapter2 = new FilterAdapter(getViewContext());
        ryTime.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        ryModule.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        ryTime.setAdapter(filterAdapter1);
        ryModule.setAdapter(filterAdapter2);

        conditionBean = new Gson().fromJson(SpUtils.getInstance().getString(AppConst.APPBASEINFO), HomeDetailslBean.class).getVideoConditions();
        //传过来的页面 是否显示筛选条件
        if (conditionBean != null && getIntent().getBooleanExtra(SHOW_FILTER, false)) {
            //以下皆为动态判断后台数据有空值 界面应正常显示
            if (conditionBean.getDurationCondition() != null) {
                if (conditionBean.getDurationCondition().getOptions() != null && conditionBean.getDurationCondition().getOptions().size() > 0 && conditionBean.getDurationCondition().getOptions().get(0) != null) {
                    conditionBean.getDurationCondition().getOptions().get(0).setSelected(true);
                    allRuleOption1 = conditionBean.getDurationCondition().getOptions().get(0);
                }
                setFilter1(conditionBean);
            } else {
                llFilter1.setVisibility(View.GONE);
            }
            if (conditionBean.getIndustryCondition() != null) {
                if (conditionBean.getIndustryCondition().getOptions() != null && conditionBean.getIndustryCondition().getOptions().size() > 0 && conditionBean.getIndustryCondition().getOptions().get(0) != null) {
                    conditionBean.getIndustryCondition().getOptions().get(0).setSelected(true);
                    allRuleOption2 = conditionBean.getIndustryCondition().getOptions().get(0);
                }
                setFilter2(conditionBean);
            } else {
                llFilter2.setVisibility(View.GONE);
            }
        } else {
            llFilterLayout.setVisibility(View.GONE);
        }
    }


    private BaseRefreshAdapter getBaseRefreshAdapter() {
        return baseRefreshAdapter = new MainAdapter(getViewContext(), mdata, R.layout.itme_main_frag);
    }


    @Override
    protected void afterCreate(Bundle savedInstanceState) {
        mids = getIntent().getIntegerArrayListExtra(CLASSIFY_ID);
        EventBus.getDefault().register(this);

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    @OnClick(R.id.ll_filter_rule)
    public void onViewClicked() {
        // setFilterTextHeightAnimation(DisplayUtils.dip2px(getViewContext(), 45), 0, animationTime);
        setFilterTextAlphaAnimation(1, 0, animationTime);
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("p1-模板列表-" + new Gson().toJson(mids)); //统计页面(仅有Activity的应用中SDK自动调用，不需要单独写。"SplashScreen"为页面名称，可自定义)
        MobclickAgent.onResume(this);          //统计时长
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("p1-模板列表-" + new Gson().toJson(mids)); // （仅有Activity的应用中SDK自动调用，不需要单独写）保证 onPageEnd 在onPause 之前调用,因为 onPause 中会保存信息。"SplashScreen"为页面名称，可自定义
        MobclickAgent.onPause(this);
    }

    private void setFilterLayoutAlphaAnimation(float form, float to, int time) {
        ValueAnimator va = ValueAnimator.ofFloat(form, to);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                if (llFilterLayout.getVisibility() == View.GONE) {
                    llFilterLayout.setVisibility(View.VISIBLE);
                }
                float h = (Float) valueAnimator.getAnimatedValue();
                llFilterLayout.setAlpha(h);
            }


        });
        va.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (form == 1) {
                    llFilterLayout.setVisibility(View.GONE);
                    llFilterLayout.setAlpha(1);
                    executeTheAnimation = false;
                    setFilterTextAlphaAnimation(0, 1, animationTime);
                    // setFilterLayoutHeightAnimation(DisplayUtils.dip2px(getContext(),90),DisplayUtils.dip2px(getContext(),40),animationTime);
                } else {
                    executeTheAnimation = false;
                }
            }
        });
        va.setDuration(time);
        va.start();
    }

    private void setFilterTextAlphaAnimation(float form, float to, int time) {
        ValueAnimator va = ValueAnimator.ofFloat(form, to);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float h = (Float) valueAnimator.getAnimatedValue();
                if (llFilterRule.getVisibility() == View.GONE) {
                    llFilterRule.setVisibility(View.VISIBLE);
                }
                llFilterRule.setAlpha(h);
            }


        });
        va.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (form == 1) {
                    //消失
                    llFilterRule.setVisibility(View.GONE);
                    llFilterRule.setAlpha(1);
                    setFilterLayoutAlphaAnimation(0, 1, animationTime);
                }
            }
        });
        va.setDuration(time);
        va.start();
    }

    public void showXRefreshViewNetWorkErrorView() {
        if (pullStatus == ON_LOAD) {
            xrefreshview.stopLoadMore();
        } else if (pullStatus == ON_REFRESH) {
            xrefreshview.stopRefresh();
        }
        xrefreshview.enableEmptyView(true);
    }

    public void showXRefreshViewNetWorkSuccessView() {
        xrefreshview.enableEmptyView(false);
    }

    //两行筛选缩起 弹出筛选条件
    private void setFilterLayoutHeightAnimation(int form, int to, int time) {
        ValueAnimator va = ValueAnimator.ofInt(form, to);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int h = (Integer) valueAnimator.getAnimatedValue();
                llFilterLayout.getLayoutParams().height = h;
                llFilterLayout.requestLayout();
            }

        });
        va.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                //偏移量5dp
                if (llFilterLayout.getHeight() < DisplayUtils.dip2px(ClassifyListActivity.this, 5)) {
                    setFilterTextHeightAnimation(0, DisplayUtils.dip2px(ClassifyListActivity.this, 45), animationTime);
                } else {
                    executeTheAnimation = false;
                }
            }
        });
        va.setDuration(time);
        va.start();
    }

    //缩起筛选条件 弹出两行筛选
    private void setFilterTextHeightAnimation(int form, int to, int time) {
        ValueAnimator va = ValueAnimator.ofInt(form, to);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int h = (Integer) valueAnimator.getAnimatedValue();
                llFilterRule.getLayoutParams().height = h;
                llFilterRule.requestLayout();
            }

        });
        va.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                //偏移量5dp
                if (llFilterRule.getHeight() < DisplayUtils.dip2px(ClassifyListActivity.this, 5)) {
                    setFilterLayoutHeightAnimation(0, DisplayUtils.dip2px(getViewContext(), 90), animationTime);
                }
            }
        });

        va.setDuration(time);
        va.start();
    }

    //设置筛选1的选中
    private void setFilter1(VideoConditionBean videoConditionBean) {
        tvFilterName1.setText(videoConditionBean.getDurationCondition().getName());
        filterAdapter1.replaceAll(videoConditionBean.getDurationCondition().getOptions());
        filterAdapter1.setonItemClickListener(new FilterAdapter.onItemClickListener() {
            @Override
            public void onItemClickListener(int position, VideoConditionBean.Option option) {
                for (VideoConditionBean.Option o : filterAdapter1.getData()) {
                    o.setSelected(false);
                }
                filterAdapter1.getItem(position).setSelected(true);
                filterAdapter1.notifyDataSetChanged();
                filterRuleOption1 = option;
                if (position == 0) filterRuleOption1 = null;
                setRuleText();
                scrollToMiddle(ryTime, position);


            }
        });
    }

    private void scrollToMiddle(RecyclerView recyclerview, int position) {
        int firstPosition = ((LinearLayoutManager) recyclerview.getLayoutManager()).findFirstVisibleItemPosition();
        int lastPosition = ((LinearLayoutManager) recyclerview.getLayoutManager()).findLastVisibleItemPosition();
        int left = recyclerview.getChildAt(position - firstPosition).getLeft();
        int right = recyclerview.getChildAt(lastPosition - position).getLeft();
        recyclerview.scrollBy((left - right) / 2, 0);
    }

    //设置筛选2的选中
    private void setFilter2(VideoConditionBean videoConditionBean) {
        tvFilterName2.setText(videoConditionBean.getIndustryCondition().getName());
        filterAdapter2.replaceAll(videoConditionBean.getIndustryCondition().getOptions());
        filterAdapter2.setonItemClickListener(new FilterAdapter.onItemClickListener() {
            @Override
            public void onItemClickListener(int position, VideoConditionBean.Option option) {
                for (VideoConditionBean.Option o : filterAdapter2.getData()) {
                    o.setSelected(false);
                }
                filterAdapter2.getItem(position).setSelected(true);
                filterAdapter2.notifyDataSetChanged();
                filterRuleOption2 = option;
                if (position == 0) filterRuleOption2 = null;
                setRuleText();
                scrollToMiddle(ryModule, position);
            }
        });
    }

    //设置筛选条件内容
    private void setRuleText() {
        if (filterRuleOption1 == null && filterRuleOption2 == null) {
            ivFilterRule.setVisibility(View.VISIBLE);
            tvFilterRule.setText("筛选");
        } else if (filterRuleOption1 == null && filterRuleOption2 != null) {
            ivFilterRule.setVisibility(View.GONE);
            tvFilterRule.setText(filterRuleOption2.getName());
        } else if (filterRuleOption1 != null && filterRuleOption2 == null) {
            ivFilterRule.setVisibility(View.GONE);
            tvFilterRule.setText(filterRuleOption1.getName());
        } else {
            ivFilterRule.setVisibility(View.GONE);
            tvFilterRule.setText(filterRuleOption2.getName() + " • " + filterRuleOption1.getName());
        }
        onLoadData();


    }

    //组装key
    private String getDurationKey() {
        if (conditionBean == null) return null;
        else if (conditionBean != null) {
            if (conditionBean.getDurationCondition() == null)
                return null;
            else return conditionBean.getDurationCondition().getRequestKey();
        }
        return null;
    }

    //组装value
    private String getDurationValue() {
        if (filterRuleOption1 == null)
            return (allRuleOption1 == null ? "" : new Gson().toJson(allRuleOption1.getValues()));
        else return new Gson().toJson(filterRuleOption1.getValues());
    }

    //组装key
    private String getTmplTypeKey() {
        if (conditionBean == null) return null;
        else if (conditionBean != null) {
            if (conditionBean.getIndustryCondition() == null)
                return null;
            else return conditionBean.getIndustryCondition().getRequestKey();
        }
        return null;
    }

    //组装value
    private String getTmplTypeValue() {
        if (filterRuleOption2 == null)
            return (allRuleOption2 == null ? "" : new Gson().toJson(allRuleOption2.getValues()));
        else return new Gson().toJson(filterRuleOption2.getValues());
    }

    public class MainAdapter extends BaseRefreshAdapter<DesignListBean.ListBean> {

        public MainAdapter(Context context, List<DesignListBean.ListBean> datas, int itemLayoutId) {
            super(context, datas, itemLayoutId);
        }

        @Override
        protected void convert(BaseRecyclerHolder viewHolder, DesignListBean.ListBean listBean, int position) {
            ImageView imageView = viewHolder.getView(R.id.id_ig);
            TextView tvName = viewHolder.getView(R.id.id_tv_name);
            TextView tvCount = viewHolder.getView(R.id.id_tv_count);
            LinearLayout layout = viewHolder.getView(R.id.ll_layout);
            layout.setBackgroundColor(getResources().getColor(R.color.apptheme));
            ImageView vip = viewHolder.getView(R.id.iv_vip_template);
            vip.setVisibility(listBean.isVipTemplate() ? View.VISIBLE : View.GONE);
            // imageView.setInitSize(listBean.getW(),listBean.getH());
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) imageView.getLayoutParams();
            layoutParams.width = listBean.getW();
            layoutParams.height = listBean.getH();
            ImageLoader.getInstance().showCircleImageWithBorder(getViewContext(), listBean.getThumb(), imageView);
            tvName.setText(listBean.getName());
            tvCount.setText(listBean.getUseCounts() + "人使用");
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onItemSelect(listBean);
                    }
                }
            });
        }
    }

}
